#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
typedef unsigned long long ULL;
const int N = 5.5e6 + 10;
int main()
{
	string str, temp1, temp2;
	cin >> str;
	temp1 = "a" + str;
	temp2 = str + "b";
	ULL ans1 = 0, ans2 = 0;
	ULL sum1 = 0, sum2 = 0;
	for (int i = 0; i < temp1.size(); i++) {
		if (temp1[i] == 'a') {
			ans1++;
		}
		else {
			sum1 += (ans1 - 1) * ans1 / 2;
		}
	}
	for (int i = 0; i < temp2.size(); i++) {
		if (temp2[i] == 'a') {
			ans2++;
		}
		else {
			sum2 += (ans2 - 1) * ans2 / 2;
		}
	}
	cout << max(sum1, sum2) << endl;
	return 0;
}
